package mo.offer_version2;

public class L62 {

    public int lastRemaining(int n, int m) {
        int f = 0;
        for (int i = 2; i != n + 1; ++i) {
            f = (m + f) % i;
        }
        return f;
    }

    public static void main(String[] args) {
        L62 test = new L62();
        System.out.println(test.lastRemaining(5, 3));
    }

}
